package com.leosoft.heatmonitor.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "role", catalog = "heatMonitor")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role implements java.io.Serializable {

	private static final long serialVersionUID = -7312003551702695365L;
	private String id;
	private String role;
	private List<User> users = new ArrayList<User>(0);

	public Role() {
	}

	public Role(String id) {
		this.id = id;
	}

	public Role(List<User> users, String id, String role) {
		super();
		this.users = users;
		this.id = id;
		this.role = role;
	}

	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	@Column(name = "role", nullable = false, length = 20)
	public String getRole() {
		return this.role;
	}

	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "roles", targetEntity = User.class)
	public List<User> getUsers() {
		return users;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

}
